package main

import (
	"github.com/gin-gonic/gin"
	"mock/gin_test/ch03/proto"
	"net/http"
)

func main() {

	r := gin.Default()

	demo := r.Group("/demo")
	{
		demo.GET("/moreJSON", moreJSON)
		demo.GET("/someProtoBuf", returnProto)
	}

	r.Run(":8888")
}

func moreJSON(c *gin.Context) {
	var msg struct {
		Name    string `json:"user"`
		Message string
		Number  int
	}
	msg.Name = "bobby"
	msg.Number = 20
	msg.Message = "json test"

	c.JSON(http.StatusOK, msg)
}

func returnProto(c *gin.Context) {

	courser := []string{"python", "go", "java"}
	user := proto.Teacher{
		Name:   "bobby",
		Course: courser,
	}

	c.ProtoBuf(http.StatusOK, &user)
}
